<?php if (!defined('insite')) die("no access"); 
/**
* top guilds 
*/
	
require "opt.php";
$db = new Connect ($config["ctype"], $config["db_host"], $config["db_name"], $config["db_user"], $config["db_upwd"],$config["odbc_driver"],$config["debug"]); 

		$gettime = time();
		$filetime = @filemtime("_dat/cach/".$_SESSION["lang"]."_topguild");
		if(!$topstr1 || ($gettime-$filetime >$config["topg"]))
		{
			ob_start();
			$content = new content();
			$content->set('|topguild_name|', topguild_name);
			$content->set('|topguild_gm|', topguild_gm);
			$content->set('|topguild_col|', topguild_col);
			$content->set('|topguild_score|', topguild_score);
			$content->set('|topguild_ali|', topguild_ali);
			$content->out_content("theme/".$config["theme"]."/them/topguild_h.them");
			
			$content->set('|siteaddress|', $config["siteaddress"]);
			
			$result12 = $db->query("SELECT TOP 100 G_Name,G_Score,G_Mark,G_Master,G_Union, number FROM guild order by G_score desc");
			$num_gx=$db->numrows($result12);

			for($i=0;$i < $num_gx ;$i++)
				{
					$row4 = $db->fetchrow($result12);
					$rank = $i+1;

					$row4[2] = GuildLogo($row4[2],$row4[0],24,$config["logotime"]);
					$resmemb = $db->query("SELECT Name,G_Status FROM GuildMember WHERE G_Name= '".$row4[0]."' ORDER BY G_Status DESC, Name DESC");

					$sostav = "<table  border='0'>";
					$kolvo = $db->numrows($resmemb);
					for ($j=0;$j<$kolvo;$j++)
					{
						$gmember = $db->fetchrow($resmemb);
						$sostav.="<tr><td width='50%' align='left'>".$guild_st[$gmember[1]]."</td><td width='50%' align='right'>".$gmember[0]."</td></tr>";
					}
					$sostav .= "</table>";
					$aliance="&nbsp;";
					if ($row4[4]!=0)
					{
						$guilds = $db->query("SELECT G_Name FROM Guild WHERE G_Union='".$row4[4]."' or number='".$row4[4]."' or G_Union='".$row4[5]."'");
						while ($g_data = $db->fetcharray($guilds))
						 if($g_data["G_Name"]!=$row4[0])$aliance .= "<div><a href='#".$g_data["G_Name"]."'>".$g_data["G_Name"]."</a></div>";
					}

				if ($rank % 2 ==0) $sh_pl = "class='lighter1'"; else $sh_pl="";
				($row4[1]=="")?$row4[1]=0:"";
				$content->set('|style|', $sh_pl);
				$content->set('|rank|', $rank);
				$content->set('|g_name|', $row4[0]);
				$content->set('|sostav|', $sostav);
				$content->set('|gm|', $row4[3]);
				$content->set('|logo|', $row4[2]);
				$content->set('|kolvo|', $kolvo);
				$content->set('|score|', $row4[1]);
				$content->set('|aliance|', $aliance);
				$content->out_content("theme/".$config["theme"]."/them/topguild_c.them");
				
				}
				$content->out_content("theme/".$config["theme"]."/them/topguild_f.them");
			$bufer = ob_get_contents();
			write_catch("_dat/cach/".$_SESSION["lang"]."_topguild",$bufer);ob_end_clean(); echo $bufer;
		}else require "_dat/cach/".$_SESSION["lang"]."_topguild";
		timing($config["topg"]);